package cn.wolfcode.trip.api.controller;

import cn.wolfcode.trip.base.domain.TravelComment;
import cn.wolfcode.trip.base.service.ITravelCommentService;
import cn.wolfcode.trip.base.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/travelComments")
public class TravelCommentController {

    @Autowired
    private ITravelCommentService travelCommentService;

    /**
     * 保存攻略文章的评论数据
     * @param travelComment
     * @return
     */
    @PostMapping
    public JsonResult save(TravelComment travelComment) {
        JsonResult result = new JsonResult();
        try {
            travelCommentService.saveOrUpdate(travelComment);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }

    /**
     * 根据游记id查询游记评论数量
     * @param travelId
     * @return
     */
    @GetMapping("{travelId}")
    public Integer queryCountByTravelId(@PathVariable Long travelId) {

        return travelCommentService.queryCountByTravelId(travelId);
    }


}
